//
// Created by Administrator on 2021/10/21.
//

#include "BoxBufferGeometry.h"

/**
 * 正立方体
 * @param size 尺寸
 */
BoxBufferGeometry::BoxBufferGeometry(float size) {
    type = GET_CLASS(__FILE__);
    name = type + "_" + id;

    this->left = -size;
    this->right = size;
    this->bottom = -size;
    this->top = size;
    this->nearplan = size;
    this->farplan = -size;
}

/**
 * 自定义立方体
 * @param left 左
 * @param right 右
 * @param bottom 下
 * @param top 上
 * @param nearplan 近
 * @param farplan 远
 */
BoxBufferGeometry::BoxBufferGeometry(float left, float right, float bottom, float top, float nearplan, float farplan) {
    type = GET_CLASS(__FILE__);
    name = type + "_" + id;

    this->left = left;
    this->right = right;
    this->bottom = bottom;
    this->top = top;
    this->nearplan = nearplan;
    this->farplan = farplan;
}

void BoxBufferGeometry::onInit() {
    //    v6----- v5
    //   /|      /|
    //  v1------v0|
    //  | |     | |
    //  | |v7---|-|v4
    //  |/      |/
    //  v2------v3
    vertices = {
            // v0-v1-v2-v3 front
            right, top, nearplan,
            left, top, nearplan,
            left, bottom, nearplan,
            right, bottom, nearplan,
            // v0-v3-v4-v5 right
            right, top, nearplan,
            right, bottom, nearplan,
            right, bottom, farplan,
            right, top, farplan,
            // v0-v5-v6-v1 up
            right, top, nearplan,
            right, top, farplan,
            left, top, farplan,
            left, top, nearplan,
            // v1-v6-v7-v2 left
            left, top, nearplan,
            left, top, farplan,
            left, bottom, farplan,
            left, bottom, nearplan,
            // v7-v4-v3-v2 bottom
            left, bottom, farplan,
            right, bottom, farplan,
            right, bottom, nearplan,
            left, bottom, nearplan,
            // v4-v7-v6-v5 back
            right, bottom, farplan,
            left, bottom, farplan,
            left, top, farplan,
            right, top, farplan
    };
    indices = {
            0, 1, 2, 0, 2, 3,
            4, 5, 6, 4, 6, 7,
            8, 9, 10, 8, 10, 11,
            12, 13, 14, 12, 14, 15,
            16, 17, 18, 16, 18, 19,
            20, 21, 22, 20, 22, 23
    };
    BufferGeometry::onInit();
}

BoxBufferGeometry::~BoxBufferGeometry() {

}



